﻿package ui;

import java.rmi.RemoteException;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;

import main.Main;
import vo.salesManager.CustomerModifyPanelVO;

import components.MyButton;
import components.MyFrame;
import components.MyPanel;

public class CustomerModifyPanel extends MyPanel{
	
	private MyButton logoutButton;
	private MyButton returnbackButton;
	private JScrollPane modifycustomerpanelScrollPane;
	private JLabel pleasemodifyLabel;
	private JLabel currentusernameLabel;
	private JLabel passwordmodifyLabel;
	private JPasswordField passwordmodifyField;
	private MyButton confirmcustomermodifyButton;
	
	@Override
	protected void initComponent() {
		logoutButton = new MyButton("注销");
		returnbackButton = new MyButton("返回");
		logoutButton.setBounds(MyFrame.WIDTH-80,0, 80, 20);
		returnbackButton.setBounds(MyFrame.WIDTH-160,0, 80, 20);
		this.add(logoutButton);
		this.add(returnbackButton);
		modifycustomerpanelScrollPane = new JScrollPane(this);
	    modifycustomerpanelScrollPane.setBounds(300, 150, 500, 450);
	    modifycustomerpanelScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		pleasemodifyLabel = new JLabel("请填写以下信息:");
		currentusernameLabel = new JLabel("当前用户名:    "+"xxx");
		passwordmodifyLabel = new JLabel("密码:");
		passwordmodifyField = new JPasswordField();
		confirmcustomermodifyButton = new MyButton("确认修改");
		pleasemodifyLabel.setBounds(10, 20, 120, 20);
		currentusernameLabel.setBounds(20, 60, 200, 20);
		passwordmodifyLabel.setBounds(20, 100, 80, 20);
		passwordmodifyField.setBounds(100, 100, 150, 25);
		confirmcustomermodifyButton.setBounds(350, 140, 100, 40);
		add(pleasemodifyLabel);
		add(currentusernameLabel);
		add(passwordmodifyLabel);
		add(passwordmodifyField);
		add(confirmcustomermodifyButton);
		
		logoutButton.setButtonAction("logout");
		returnbackButton.setButtonAction("toCustomerQuery");
		confirmcustomermodifyButton.setButtonAction("modifyCustomer");
	}
	@Override
	protected void updateVO() {
		CustomerModifyPanelVO cmpvo=null;
		try {
			cmpvo = Main.getLogic().getCmpvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		cmpvo.setPassword(passwordmodifyField.getText());
		try {
			Main.getLogic().setCmpvo(cmpvo);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

}
